package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：
 *
 * @package: cn.wolfcode.trip.base.service.impl
 * @author: Patch
 * @date: 2019/5/19 15:28
 * 总结:
 */
@Service
public class RegionServiceImpl implements IRegionService {
    @Autowired
    private RegionMapper regionMapper;

    @Override
    public void saveOrUpdate(Region region) {
        if (region.getId() == null) {
            // 新增
            regionMapper.insert(region);
        } else {
            // 更新
            regionMapper.updateByPrimaryKey(region);
        }
    }

    @Override
    public List<Region> listAll(Long state) {
        return regionMapper.selectAll(state);
    }

    @Override
    public Region get(Long id) {
        return regionMapper.selectByPrimaryKey(id);
    }

    @Override
    public void delete(Long id) {
        regionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List listByParentId(Long parentId) {
        return regionMapper.selectByParentId(parentId);
    }

    @Override
    public void updateState(Long id, int state) {
        regionMapper.updateState(id, state);
    }
}
